1
|
|
|
import React from 'react'; |
2
|
|
|
import {ILanguageSetup} from '../Language/ChangeLanguageSetup'; |
3
|
|
|
import {IPageData} from '../Router/Router'; |
4
|
|
|
import Container from './Container'; |
5
|
|
|
import ModuleLoader from './ModuleLoader'; |
6
|
|
|
import ApplicationView, {IAdapter} from './View/Application'; |
7
|
|
|
import Model from './View/Application/Model'; |
8
|
|
|
|
9
|
|
|
interface IProperties { |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
interface IState { |
13
|
|
|
loadedLanguage: string, |
14
|
|
|
menuOpen: boolean, |
15
|
|
|
loadedPage: typeof React.Component | null, |
16
|
|
|
shownPage: string |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
export default class Application extends React.Component<IProperties, IState> { |
20
|
|
|
adapter: IAdapter; |
21
|
|
|
moduleLoader: ModuleLoader; |
22
|
|
|
|
23
|
|
|
constructor(props: IProperties) { |
24
|
|
|
super(props); |
25
|
|
|
|
26
|
|
|
this.state = { |
27
|
|
|
loadedLanguage: Container.language.observer.value.languageCode, |
28
|
|
|
menuOpen: Container.menuOpenState.value, |
29
|
|
|
loadedPage: null, |
30
|
|
|
shownPage: '' |
31
|
|
|
}; |
32
|
|
|
this.adapter = Container.applicationAction.adapter; |
33
|
|
|
this.moduleLoader = Container.moduleLoader; |
34
|
|
|
|
35
|
|
|
Container.language.adapter.addListener(this.onLanguageLoaded.bind(this)); |
36
|
|
|
Container.moduleStateAdapter.addListener(this.onModuleLoaded.bind(this)); |
37
|
|
|
Container.router.adapter.addListener(this.onPageChanged.bind(this)); |
38
|
|
|
Container.menuOpenStateAdapter.onChange = this.onMenuChange.bind(this); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
componentDidMount(): void { |
42
|
|
|
Container.language.changeLanguageSetup.interact({languageCode: 'de-de'}, {}).then(); |
43
|
|
|
const homePage: IPageData = { |
44
|
|
|
depth: 0, |
45
|
|
|
name: 'home', |
46
|
|
|
url: './HelloWorld' |
47
|
|
|
}; |
48
|
|
|
Container.router.registry.registerPage(homePage); |
49
|
|
|
Container.router.registry.registerPage({ |
50
|
|
|
depth: 1, |
51
|
|
|
name: 'settings', |
52
|
|
|
url: './Settings' |
53
|
|
|
}); |
54
|
|
|
Container.router.observer.value = homePage; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
onLanguageLoaded(oldValue: ILanguageSetup, newValue: ILanguageSetup) { |
58
|
|
|
this.setState({loadedLanguage: newValue.languageCode}); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
onMenuChange(oldValue: boolean, newValue: boolean) { |
62
|
|
|
this.setState({menuOpen: newValue}); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
onModuleLoaded(oldValue: typeof React.Component | null, newValue: typeof React.Component | null) { |
66
|
|
|
this.setState({loadedPage: newValue}); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
onPageChanged(oldValue: IPageData, newValue: IPageData) { |
70
|
|
|
this.moduleLoader.loadModule(newValue.url).then(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
render(): React.ReactNode { |
74
|
|
|
const model: Model = Container.applicationPresenter.present(); |
75
|
|
|
|
76
|
|
|
return <ApplicationView model={model} adapter={this.adapter} />; |
77
|
|
|
} |
78
|
|
|
} |